User XXXX has already more than 'max_user_connections' active connections
op mijn site kunnen mensen plaatjes uploaden, maar als ik meerdere plaatjes achter elkaar upload, krijg ik na +- 6x een plaatje te uploaden, de volgende foutmelding:
Error:
"User "username" has already more than 'max_user_connections' active connections"
Als ik dan gewoon de hoofdpagina wil zien krijg ik dezelfde melding.
Hier de code die ik gebruik om te uploaden.
<script type="text/javascript">
function highlight(field) {
field.focus();
field.select();
}
-->
</script>
<table width="100%" border="1" cellspacing="0" bordercolor="#000000" bgcolor="#CCCCCC">
<tr>
<td width="60%" height="60" valign="top"><p>
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
include "includes/filter.php";
//Image Upload Script
//Created by Lappy512
//Part of ImageHostSript.
//See conf_global.php
?>
include "includes/filter.php";
//Image Upload Script
//Created by Lappy512
//Part of ImageHostSript.
//See conf_global.php
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
// $userfile is where the file is on the webserver
$userfile = $HTTP_POST_FILES['imagefile']['tmp_name'];
// $userfile is original file name
$userfile_name = $HTTP_POST_FILES['imagefile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['imagefile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['imagefile']['type'];
// $comments are the comments, but we need logic if there aren't comments.
if($_POST['comments'])
{
$comments = $_POST['comments'];
if (get_magic_quotes_gpc() == 0)
{
$comments = addslashes($comments);
}
$comments = nl2br($comments);
}
else
{
//they didn't comment
$comments = 'Geen Commentaar bij dit plaatje';
}
// $url are is the URL, but we need logic if there isn't one.
if($_POST['url'])
{
$url = $_POST['url'];
if (get_magic_quotes_gpc() == 0)
{
$url = addslashes($url);
}
$url = nl2br($url);
}
else
{
//they didn't comment
$url = 'http://www.pornholio.be';
}
//Sporadic MIME-TYPES?
if ($userfile_type == 'image/x-png')
{
$userfile_type = 'image/png';
}
if ($userfile_type == 'image/pjpeg')
{
$userfile_type = 'image/jpeg';
}
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['imagefile']['error'];
//PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less
if ($userfile_error > 0)
{
echo 'Problem: ';
switch($userfile_error)
{
case 1: echo 'File exceeded Maximum upload filesize'; break;
case 2: echo 'File exceeded Maximum upload filesize'; break;
case 3: echo 'File partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
//end of code for 4.2.0+
switch($userfile_type)
{
case 'image/gif':
break;
case 'image/png':
break;
case 'image/jpeg':
break;
case 'image/bmp':
echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. ";
exit;
default:
echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. ";
echo "<br> your file has a MIME-TYPE of $userfile_type";
exit;
break;
}
//Lets try connecting to mySQL
@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']);
//IT"S NOT WORKING!
if (!$db)
{
die("error");
mysql_close();
}
mysql_select_db($mysql['db']);
//We need to get a date for our Database
$date = time();
//Put the data there!
$query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `url`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $url . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error");
mysql_close();
}
$userfile_name = mysql_insert_id();
//put the file where we want it
$upfile = './uploads/' . $userfile_name;
//need PHP 4.0.3
if(is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
mysql_close();
}
}
else
{
echo 'Problem: Possible File upload attack. Filename: '.$userfile_name;
exit;
mysql_close();
}
echo '<br>Het bestand is succesvol geupload<br/><br/>';
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//files update
$files = $stat['files'] + 1;
$query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//1337 h4x0rs can resize everything, even though we can't outputz0rz to everything.
//Resample it now!
// The file
$filename = $upfile;
$thumb = './uploads/' . 'thumb_' . $userfile_name;
// Set a maximum height and width
$width = 150;
$height = 150;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig < $width) && ($height_orig < $height))
{
$width = $width_orig;
$height = $height_orig;
}
else
{
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
if($userfile_type == 'image/jpeg')
{
$image = imagecreatefromjpeg($filename);
}
if($userfile_type == 'image/png')
{
$image = imagecreatefrompng($filename);
}
if($userfile_type == 'image/gif')
{
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if($userfile_type == 'image/jpeg')
{
imagejpeg($image_p, $thumb);
}
if($userfile_type == 'image/png' or $userfile_type == 'image/gif')
{
imagepng($image_p, $thumb);
$userfile_type = 'image/png';
}
$userfile_size = filesize($upfile);
$id = $userfile_name;
//Put the data there!
$query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error 2 " . mysql_error());
mysql_close();
}
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
?>
// $userfile is where the file is on the webserver
$userfile = $HTTP_POST_FILES['imagefile']['tmp_name'];
// $userfile is original file name
$userfile_name = $HTTP_POST_FILES['imagefile']['name'];
// $userfile_size is size in bytes
$userfile_size = $HTTP_POST_FILES['imagefile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $HTTP_POST_FILES['imagefile']['type'];
// $comments are the comments, but we need logic if there aren't comments.
if($_POST['comments'])
{
$comments = $_POST['comments'];
if (get_magic_quotes_gpc() == 0)
{
$comments = addslashes($comments);
}
$comments = nl2br($comments);
}
else
{
//they didn't comment
$comments = 'Geen Commentaar bij dit plaatje';
}
// $url are is the URL, but we need logic if there isn't one.
if($_POST['url'])
{
$url = $_POST['url'];
if (get_magic_quotes_gpc() == 0)
{
$url = addslashes($url);
}
$url = nl2br($url);
}
else
{
//they didn't comment
$url = 'http://www.pornholio.be';
}
//Sporadic MIME-TYPES?
if ($userfile_type == 'image/x-png')
{
$userfile_type = 'image/png';
}
if ($userfile_type == 'image/pjpeg')
{
$userfile_type = 'image/jpeg';
}
// $userfile_error is any error encountered
$userfile_error = $HTTP_POST_FILES['imagefile']['error'];
//PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less
if ($userfile_error > 0)
{
echo 'Problem: ';
switch($userfile_error)
{
case 1: echo 'File exceeded Maximum upload filesize'; break;
case 2: echo 'File exceeded Maximum upload filesize'; break;
case 3: echo 'File partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
//end of code for 4.2.0+
switch($userfile_type)
{
case 'image/gif':
break;
case 'image/png':
break;
case 'image/jpeg':
break;
case 'image/bmp':
echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. ";
exit;
default:
echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. ";
echo "<br> your file has a MIME-TYPE of $userfile_type";
exit;
break;
}
//Lets try connecting to mySQL
@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']);
//IT"S NOT WORKING!
if (!$db)
{
die("error");
mysql_close();
}
mysql_select_db($mysql['db']);
//We need to get a date for our Database
$date = time();
//Put the data there!
$query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `url`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $url . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error");
mysql_close();
}
$userfile_name = mysql_insert_id();
//put the file where we want it
$upfile = './uploads/' . $userfile_name;
//need PHP 4.0.3
if(is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
mysql_close();
}
}
else
{
echo 'Problem: Possible File upload attack. Filename: '.$userfile_name;
exit;
mysql_close();
}
echo '<br>Het bestand is succesvol geupload<br/><br/>';
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//files update
$files = $stat['files'] + 1;
$query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//1337 h4x0rs can resize everything, even though we can't outputz0rz to everything.
//Resample it now!
// The file
$filename = $upfile;
$thumb = './uploads/' . 'thumb_' . $userfile_name;
// Set a maximum height and width
$width = 150;
$height = 150;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig < $width) && ($height_orig < $height))
{
$width = $width_orig;
$height = $height_orig;
}
else
{
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
if($userfile_type == 'image/jpeg')
{
$image = imagecreatefromjpeg($filename);
}
if($userfile_type == 'image/png')
{
$image = imagecreatefrompng($filename);
}
if($userfile_type == 'image/gif')
{
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if($userfile_type == 'image/jpeg')
{
imagejpeg($image_p, $thumb);
}
if($userfile_type == 'image/png' or $userfile_type == 'image/gif')
{
imagepng($image_p, $thumb);
$userfile_type = 'image/png';
}
$userfile_size = filesize($upfile);
$id = $userfile_name;
//Put the data there!
$query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error 2 " . mysql_error());
mysql_close();
}
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
?>
<FORM action="../nowhere" method="post" class="table_decoration">
<b><a href="">Click hier om nog een foto te uploaden</a></b><br>
<br/>HTML:<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="<a href='viewer.php?id='><img src='thumb/.jpeg'></a>">
<br/>BBCODE:<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="[url=viewer.php?id=][/url]">
<br/>Thumbnail for Forums(1):<br>
<input onclick="highlight(this);" style="width: 500px;" size="80" value="[URL=viewer.php?id=]
Zoiezo zou je kunnen beginnen door het script eens om te zetten naar de huidige standaard. $HTTP_POST_FILES kan je bijv. vervangen door $_FILES(). En je query's kunnen wat mij betreft ook wel wat netter en efficienter.
Overigens heeft jou probleem weinig met het script te maken. Je mysql heeft een maximaal aantal connecties wat hij tegelijkertijd wilt verwerken van één gebruiker. Verhoog die en je probleem is opgelost.
en waarom sluit je je mysql connectie zo vaak als je hem in hetzelfde script toch blijft gebruiken?
Sorry voor de rare post. Ik drukte per ongeluk op enter en toen stond ie er.
Ik heb hem een beetje uitgekleed en heb dat $_FILES() nu ook gebruikt. Ben nog niet zo heel lang bezig met php. Ben bezig met een cursus en heb dit script van internet gehaald en een beetje aangepast.
Ik host mijn website bij een derde en kan de max_users niet aanpassen. Ik denk zelf dat het iets heeft te maken met het feit dat ik de connectie na het uploaden moet verbreken.
Ik hoop dat er een goede oplossing gevonden kan worden.
Hierbij het uitgekledescript:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<?php
// $userfile is where the file is on the webserver
$userfile = $_FILES()['imagefile']['tmp_name'];
// $userfile is original file name
$userfile_name = $_FILES()['imagefile']['name'];
// $userfile_size is size in bytes
$userfile_size = $_FILES()['imagefile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $_FILES()['imagefile']['type'];
// $comments are the comments, but we need logic if there aren't comments.
if($_POST['comments'])
{
$comments = $_POST['comments'];
if (get_magic_quotes_gpc() == 0)
{
$comments = addslashes($comments);
}
$comments = nl2br($comments);
}
else
{
//they didn't comment
$comments = 'Geen Commentaar bij dit plaatje';
}
// $url are is the URL, but we need logic if there isn't one.
if($_POST['url'])
{
$url = $_POST['url'];
if (get_magic_quotes_gpc() == 0)
{
$url = addslashes($url);
}
$url = nl2br($url);
}
else
{
//they didn't comment
$url = 'http://www.pornholio.be';
}
//Sporadic MIME-TYPES?
if ($userfile_type == 'image/x-png')
{
$userfile_type = 'image/png';
}
if ($userfile_type == 'image/pjpeg')
{
$userfile_type = 'image/jpeg';
}
// $userfile_error is any error encountered
$userfile_error = $_FILES()['imagefile']['error'];
//PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less
if ($userfile_error > 0)
{
echo 'Problem: ';
switch($userfile_error)
{
case 1: echo 'File exceeded Maximum upload filesize'; break;
case 2: echo 'File exceeded Maximum upload filesize'; break;
case 3: echo 'File partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
//end of code for 4.2.0+
switch($userfile_type)
{
case 'image/gif':
break;
case 'image/png':
break;
case 'image/jpeg':
break;
case 'image/bmp':
echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. ";
exit;
default:
echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. ";
echo "<br> your file has a MIME-TYPE of $userfile_type";
exit;
break;
}
//Lets try connecting to mySQL
@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']);
//IT"S NOT WORKING!
if (!$db)
{
die("error");
mysql_close();
}
mysql_select_db($mysql['db']);
//We need to get a date for our Database
$date = time();
//Put the data there!
$query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `url`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $url . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error");
mysql_close();
}
$userfile_name = mysql_insert_id();
//put the file where we want it
$upfile = './uploads/' . $userfile_name;
//need PHP 4.0.3
if(is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
mysql_close();
}
}
else
{
echo 'Problem: Possible File upload attack. Filename: '.$userfile_name;
exit;
mysql_close();
}
echo '<br>Het bestand is succesvol geupload<br/><br/>';
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//files update
$files = $stat['files'] + 1;
$query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//1337 h4x0rs can resize everything, even though we can't outputz0rz to everything.
//Resample it now!
// The file
$filename = $upfile;
$thumb = './uploads/' . 'thumb_' . $userfile_name;
// Set a maximum height and width
$width = 150;
$height = 150;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig < $width) && ($height_orig < $height))
{
$width = $width_orig;
$height = $height_orig;
}
else
{
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
if($userfile_type == 'image/jpeg')
{
$image = imagecreatefromjpeg($filename);
}
if($userfile_type == 'image/png')
{
$image = imagecreatefrompng($filename);
}
if($userfile_type == 'image/gif')
{
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if($userfile_type == 'image/jpeg')
{
imagejpeg($image_p, $thumb);
}
if($userfile_type == 'image/png' or $userfile_type == 'image/gif')
{
imagepng($image_p, $thumb);
$userfile_type = 'image/png';
}
$userfile_size = filesize($upfile);
$id = $userfile_name;
//Put the data there!
$query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error 2 " . mysql_error());
mysql_close();
}
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
?>
// $userfile is where the file is on the webserver
$userfile = $_FILES()['imagefile']['tmp_name'];
// $userfile is original file name
$userfile_name = $_FILES()['imagefile']['name'];
// $userfile_size is size in bytes
$userfile_size = $_FILES()['imagefile']['size'];
// $userfile_type is mime type e.g. image/gif
$userfile_type = $_FILES()['imagefile']['type'];
// $comments are the comments, but we need logic if there aren't comments.
if($_POST['comments'])
{
$comments = $_POST['comments'];
if (get_magic_quotes_gpc() == 0)
{
$comments = addslashes($comments);
}
$comments = nl2br($comments);
}
else
{
//they didn't comment
$comments = 'Geen Commentaar bij dit plaatje';
}
// $url are is the URL, but we need logic if there isn't one.
if($_POST['url'])
{
$url = $_POST['url'];
if (get_magic_quotes_gpc() == 0)
{
$url = addslashes($url);
}
$url = nl2br($url);
}
else
{
//they didn't comment
$url = 'http://www.pornholio.be';
}
//Sporadic MIME-TYPES?
if ($userfile_type == 'image/x-png')
{
$userfile_type = 'image/png';
}
if ($userfile_type == 'image/pjpeg')
{
$userfile_type = 'image/jpeg';
}
// $userfile_error is any error encountered
$userfile_error = $_FILES()['imagefile']['error'];
//PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less
if ($userfile_error > 0)
{
echo 'Problem: ';
switch($userfile_error)
{
case 1: echo 'File exceeded Maximum upload filesize'; break;
case 2: echo 'File exceeded Maximum upload filesize'; break;
case 3: echo 'File partially uploaded'; break;
case 4: echo 'No File Uploaded'; break;
}
exit;
}
//end of code for 4.2.0+
switch($userfile_type)
{
case 'image/gif':
break;
case 'image/png':
break;
case 'image/jpeg':
break;
case 'image/bmp':
echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. ";
exit;
default:
echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. ";
echo "<br> your file has a MIME-TYPE of $userfile_type";
exit;
break;
}
//Lets try connecting to mySQL
@ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']);
//IT"S NOT WORKING!
if (!$db)
{
die("error");
mysql_close();
}
mysql_select_db($mysql['db']);
//We need to get a date for our Database
$date = time();
//Put the data there!
$query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `url`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $url . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error");
mysql_close();
}
$userfile_name = mysql_insert_id();
//put the file where we want it
$upfile = './uploads/' . $userfile_name;
//need PHP 4.0.3
if(is_uploaded_file($userfile))
{
if (!move_uploaded_file($userfile, $upfile))
{
echo 'Problem: Could not move file to destination directory';
exit;
mysql_close();
}
}
else
{
echo 'Problem: Possible File upload attack. Filename: '.$userfile_name;
exit;
mysql_close();
}
echo '<br>Het bestand is succesvol geupload<br/><br/>';
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//files update
$files = $stat['files'] + 1;
$query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
//1337 h4x0rs can resize everything, even though we can't outputz0rz to everything.
//Resample it now!
// The file
$filename = $upfile;
$thumb = './uploads/' . 'thumb_' . $userfile_name;
// Set a maximum height and width
$width = 150;
$height = 150;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if(($width_orig < $width) && ($height_orig < $height))
{
$width = $width_orig;
$height = $height_orig;
}
else
{
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
if($userfile_type == 'image/jpeg')
{
$image = imagecreatefromjpeg($filename);
}
if($userfile_type == 'image/png')
{
$image = imagecreatefrompng($filename);
}
if($userfile_type == 'image/gif')
{
$image = imagecreatefromgif($filename);
}
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
if($userfile_type == 'image/jpeg')
{
imagejpeg($image_p, $thumb);
}
if($userfile_type == 'image/png' or $userfile_type == 'image/gif')
{
imagepng($image_p, $thumb);
$userfile_type = 'image/png';
}
$userfile_size = filesize($upfile);
$id = $userfile_name;
//Put the data there!
$query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');";
//QUERY!
$result = mysql_query($query);
if (!$result)
{
die("MySQL insert error 2 " . mysql_error());
mysql_close();
}
//get current stats
$query = "SELECT * FROM `stat_cache`";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Select error");
mysql_close();
}
$stat = mysql_fetch_array($result);
//update statistics
//space update
$totalspace = $stat['space'] + $userfile_size;
$query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1";
$result = mysql_query($query);
if (!$result)
{
die("MySQL Update error");
mysql_close();
}
?>
Ten eerste, wanneer je verbinding maakt, zal de functie eerst proberen een (persistente) link te openen die al open staat met dezelfde host, username en password. Als er een gevonden wordt zal een identifier ervoor worden teruggegeven, in plaats van een nieuwe verbinding te openen.
Ten tweede, de verbinding met de SQL server zal niet worden gesloten wanneer de executie van het script klaar is. In plaats daarvan zal de link open blijven voor toekomstig gebruik (mysql_close() zal geen links sluiten die werden gemaakt door mysql_pconnect()).
mysql_connect() gebruiken dus :).l
:( Je bent me net voor. Ik wou presies 't zelfde posten.
Je wordt dan ook gedwongen om correcte tabel- en kolomnamen te gebruiken, daar kun je in de toekomst nog een hoop voordeel van hebben.
Nooit meer backtics in je queries zetten!
Bedankt voor de hulp. Het probleem is opgelost. @frank
Je hebt helemaal gelijk, maar ik wil voor de rest niets meer aan die website doen. Ik heb een nieuw project waar ik mee aan de slag ga en voor deze website ga ik gewoon mensen inhuren die het goed doen. Ben gewoon een beginneling en heb helemaal de kennis niet. Wilde gewoon even stoeien met PHP en wat ik tot nu toe heb opgezet is voldoende. Bedankt allemaal